package cn.deepxi.org.service.impl;

import cn.deepxi.base.query.BaseQuery;
import cn.deepxi.base.service.impl.BaseServiceImpl;
import cn.deepxi.org.domain.Department;
import cn.deepxi.org.mapper.DepartmentMapper;
import cn.deepxi.org.query.DepartmentQuery;
import cn.deepxi.org.service.IDeptService;
import cn.deepxi.utils.QueryResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class DeptServiceImpl extends BaseServiceImpl<Department> implements IDeptService {
    @Autowired
    private DepartmentMapper departmentMapper;
    @Override
    public void save(Department d) {
        departmentMapper.save(d);
    }

    @Override
    public void remove(Long id) {
        departmentMapper.remove(id);
    }

    @Override
    public void update(Department d) {
        departmentMapper.update(d);
    }



    @Override
    public List<Department> loadAll() {
        return departmentMapper.loadAll();
    }

    @Override
    public QueryResult<Department> queryPage(BaseQuery departmentQuery) {
        //分页及高级查询相关数据
        List<Department> data = departmentMapper.queryData(departmentQuery);
        //总条数（包括高级查询和普通查询）
        Long queryCount = departmentMapper.queryCount(departmentQuery);
        return new QueryResult<>(queryCount,data);
    }
//批量删除
    @Override
    @Transactional
    public void batchRemove(Long[] ids) {
        departmentMapper.batchRemove(ids);
    }
//级联树
    @Override
    public List<Department> loadDeptTree() {
        return departmentMapper.loadDeptTree();
    }
}
